import Payment from '@doctorwork/utils/payment';
import { effects } from 'dva-core/saga';
import { router } from '@doctorwork/saga';

import endpoints from '../endpoints';

const api = endpoints;
const payment = new Payment({ api, router, effects });

export default {
    namespace: 'payment',
    state: {},
    reducers: {
        // 同步到内存中
        save(state, { payload }) {
            return Object.assign({}, state, payload);
        }
    },
    effects: {
        *pay({ payload }, { take }) {
            yield payment.pay(payload);
            const res = yield take('PAYMENT_SUCCESS');
            return res;
        }
    }
};
